<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- computed 计算属性 有缓存，只有依赖的值发生变化时，才会执行 
        methods  方法  没有缓存  只要调用就会执行
        watch 监听 监听的值发生变化时，会执行
    -->
</head>
<body>
    <div id="app">
        {{address}}
        {{address}}
        {{address}}
        {{address}}
        {{address}}
        {{address}}
    </div>
    <script src="./vue.js"></script>
    <script>
        let vm = new Vue({
            el:'#app',
            data:{
                city:'北京',
                area:'朝阳区'
            },
            methods:{
                // address(){
                //     console.log("methods address")
                //     return `${this.city}-${this.area}`
                // }
                
            },
            computed:{
                address:{
                    get(){
                        return `${this.city}-${this.area}`
                    },
                    set(val){
                        this.city = val.split('-')[0];
                        this.area = val.split('-')[1];
                    }
                }
                // address(){
                //     console.log("address")
                //     return `${this.city}-${this.area}`
                // }
            },
            watch:{
                // city(newVal,oldVal){
                //     this.address = `${newVal}-${this.area}`     
                // },
                // area(newVal,oldVal){
                //     this.address = `${this.city}-${newVal}`  
                // }
            }
        })
    </script>
</body>
</html>